package com.luke.star.task;

import java.util.UUID;

import javax.annotation.Resource;

import org.apache.logging.log4j.ThreadContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.luke.star.serviceImpl.StAssignmentService;
import com.luke.star.util.DateUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 目标分解周期性自动加星，暂时默认周期为1天
 *
 */

@Slf4j
@Component
public class StAssignmentTaskJob {
	
	@Resource
	private StAssignmentService StAssignmentService;
	
	
	@Scheduled(cron="${st.assignment.JobCron}")
	public void work() {
		String uuid = UUID.randomUUID().toString();
		ThreadContext.clearStack();
		ThreadContext.push(uuid);
		log.info("开始收集分解任务的星星,开始时间:{}", DateUtil.getNowDateStr(DateUtil.DATETIME_FORMAT_YYYY_MM_DD_HH_MM_SS));
		try {
			StAssignmentService.runAssignment();
		} catch (Exception e) {
			log.error("收集分解任务星星出现异常，",e);
		}
		long t1 = System.currentTimeMillis();
		String time = (System.currentTimeMillis()-t1)/1000+"s";
		log.info("结束收集分解任务的星星,耗时{},结束时间:{}",time, DateUtil.getNowDateStr(DateUtil.DATETIME_FORMAT_YYYY_MM_DD_HH_MM_SS));
		ThreadContext.pop();
	}
	
	
	

}
